home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Documentation / DirectX9 / directx9_c.chm / directx / code / pvutil.js < prev    next >
Encoding:
Text File  |  2004-09-30  |  6.5 KB  |  303 lines

  1. <![CDATA[
  2.  
  3. // BUGBUG: Need to create CPVResults/CCVResults to store lookup data and CPV/CCV to encapsulate Lookup
  4. // BUGBUG: Rather than accessing global goLookup, pass this into the CPV and CCV constructor
  5.  
  6. // Encapsulation of possible value results data
  7. function CPVData()
  8. {
  9. //    this.Init();
  10. }
  11.  
  12. CPVData.prototype.Init = function()
  13. {
  14.     this.caption = "";
  15.     this.devlang = "";
  16.     this.error = "";
  17.     this.className = "";
  18.     this.pid = "";
  19.     this.rid = "";
  20. }
  21.  
  22. function CCVData()
  23. {
  24. //    this.Init();
  25. }
  26.  
  27. CCVData.prototype.Init = function()
  28. {
  29.     this.caption = "";
  30.     this.devlang = "";
  31.     this.error = "";
  32.     this.cvid = "";
  33.     this.rid = "";
  34. }
  35.  
  36. // Lookup the composite value associated with the xref
  37. function LookupCV(oSrc, oData, sCurLang)
  38. {    
  39.     oData.Init();
  40.     
  41.     var sCVID = oData.caption = oSrc.getAttribute("cvid");
  42.     if (!sCVID)
  43.     {
  44.         oData.error = "expected cvid was not specified.";
  45.         return false;
  46.     }
  47.  
  48.     var sRID = oData.rid = oSrc.getAttribute("rid");
  49.     if (!IsSelfReference(sRID))
  50.     {        
  51.         if (!goLookup.RetrieveTarget(sRID))
  52.         {
  53.             oData.error = "unable to find rid '" + sRID + "' among targets.";
  54.             return false;
  55.         }
  56.     }
  57.     else
  58.     {
  59.         var oNode = ownerDocument.selectSingleNode("/inetsdk:topic/content/params/param[@get]/pv[@type='composite']/cv[@name='" + sCVID + "']");
  60.         if (!oNode)
  61.         {
  62.             oData.error = "cvid '" + sCVID + "' not found.";
  63.             return false;
  64.         }
  65.     }
  66.  
  67.     return true;
  68. }
  69.  
  70. function GetCVCaption(oSrc, oData)
  71. {
  72.     return oData.caption;
  73. }
  74.  
  75. // Lookup the possible value associated with the specified xref
  76. function LookupPV(oSrc, oData, sCurLang)
  77. {
  78.     oData.Init();
  79.     
  80.     var sDevLang = oSrc.getAttribute("devlang"); // author can override the devlang (or specify it in a lang-neutral topic)
  81.     if (!sDevLang)
  82.     {
  83.         sDevLang = sCurLang;
  84.     }
  85.     oData.devlang = sDevLang; // the devlang as defined by the current template
  86.  
  87.     var sPV = oData.caption = oSrc.getAttribute("pvid");
  88.     // the following should never happen
  89.     if (!sPV)
  90.     {
  91.         oData.error = "expected pvid was not specified.";
  92.         return false;
  93.     }
  94.  
  95.     // BUGBUG: Should first determine if the xref is to a doc of type method, function, struct, or enum
  96.     // BUGBUG: Use that info to get the appropriate attribute (@pid, @mid, @cid)
  97.     var sRID = oData.rid = oSrc.getAttribute("rid");    
  98.     var bSelfRef = IsSelfReference(sRID);
  99.     var sType;
  100.  
  101.     var sPVType = oSrc.getAttribute("pvtype");
  102.  
  103.     if (bSelfRef)
  104.     {
  105.         sType = ownerDocument.selectSingleNode("/inetsdk:topic/metadata/@type").value;        
  106.     }
  107.     else
  108.     {
  109.         if (!sPVType)
  110.         {
  111.             oData.error = "specify pvtype=(range|literal|flag) when pv reference points to remote topic";
  112.             return false;
  113.         }
  114.  
  115.         var oTarget;
  116.         if (!(oTarget = goLookup.RetrieveTarget(sRID)))
  117.         {
  118.             oData.error = "unable to find rid '" + sRID + "' among targets.";
  119.             return false;
  120.         }
  121.         else
  122.         {
  123.             sType = oTarget.getAttribute("type");
  124.         }
  125.     }
  126.  
  127.     var sQuery = "/inetsdk:topic/content/";
  128.     var sMID;
  129.     switch(sType)
  130.     {
  131.     case 'struct':
  132.         sMID = oData.mid = oSrc.getAttribute("mid");
  133.         if (!sMID)
  134.         {
  135.             oData.error = "expected @mid not found.";
  136.             return false;
  137.         }
  138.         sQuery += "members/member[@name='" + sMID + "'][pv]";
  139.         break;
  140.     case 'property':
  141.     case 'method':
  142.     case 'function':
  143.         sMID = oData.pid = oSrc.getAttribute("pid");
  144.         if (!sMID)
  145.         {
  146.             oData.error = "expected @pid not found.";
  147.             return false;
  148.         }
  149.         sQuery += "params/param[@name='" + sMID + "'][pv]";
  150.         break;
  151.     case 'isv_element':
  152.         sMID = oData.aid = oSrc.getAttribute("aid");
  153.         if( !sMID )
  154.         {
  155.             oData.error = "expected @aid not found.";
  156.             return false;
  157.         }
  158.         sQuery += "attribs/attrib[@name='" + sMID + "'][pv]";
  159.         break;
  160.     case 'htmldeclaration':
  161.         sMID = oData.aid = oSrc.getAttribute("aid");
  162.         if( !sMID )
  163.         {
  164.             oData.error = "expected @aid not found.";
  165.             return false;
  166.         }
  167.         sQuery += "attribs/attrib[@name='" + sMID + "'][pv]";
  168.         break;
  169.     default:
  170.         oData.error = "type '" + sType + "' not supported.";
  171.         return false;
  172.     }
  173.         
  174.  
  175.     if (bSelfRef)
  176.     {
  177.         // find the pv among the params/members in the current topic
  178.         var oMember = ownerDocument.selectSingleNode(sQuery);
  179.         if (!oMember)
  180.         {
  181.             oData.error = "param/member '" + sMID + "' not found in current topic.";
  182.             return false;        
  183.         }
  184.  
  185.         // lookup name preferentially
  186.         var oPV;
  187.         if (oPV = oMember.selectSingleNode("pv[@name='" + sPV + "']"))
  188.         {        
  189.             if (sDevLang == 'scr')
  190.             {
  191.                 var sValue = oPV.getAttribute('value');
  192.                 if (!sValue)
  193.                 {
  194.                     oDest.error = "unable to retrieve value from name '" + sPV + "'.";
  195.                     return false;
  196.                 }
  197.  
  198.                 sPV = oData.caption = sValue;            
  199.             }
  200.         }
  201.         else if (oPV = oMember.selectSingleNode("pv[@value='" + sPV + "']"))
  202.         {
  203.             // BUGBUG: Disallow this in the C++ case? It's what scripters want but probably not what C++ programmers want.
  204.         }
  205.         else if (oPV = oMember.selectSingleNode("pv[@rid='" + sPV + "']"))
  206.         {
  207.             var oFlag = ownerDocument.selectSingleNode("/inetsdk:topic/flags/flag[@id='" + sPV + "']");
  208.             if (!oFlag)
  209.             {
  210.                 oData.error = "flag with id '" + sPV + "' not found.";
  211.                 return false;
  212.             }
  213.  
  214.             var sAttr = aFlagAttrMap[sDevLang];
  215.             if (!sAttr)
  216.             {
  217.                 oDest.error = "devlang '" + sDevLang + "' not found in flag map.";
  218.                 return false;
  219.             }
  220.             
  221.             var sCaption = oFlag.getAttribute(sAttr);
  222.             if (!sCaption)
  223.             {
  224.                 oData.error = "flag with id '" + sPV + "' missing '" + sAttr + "' attribute.";
  225.                 return false;
  226.             }
  227.             else
  228.             {
  229.                 sPV = oData.caption = sCaption;
  230.             }
  231.         }
  232.         else
  233.         {
  234.             oData.error = "pv '" + sPV + "' not found.";
  235.             return false;
  236.         }
  237.     }
  238.  
  239.     if (!sPVType && oPV)
  240.     {
  241.         sPVType = oPV.getAttribute("type");
  242.     }
  243.     
  244.     if (!MapPVTypeToCSSClass(sPVType, oData, sDevLang))
  245.     {
  246.         return false;
  247.     }
  248.     
  249.     return true;
  250. }
  251.  
  252. // given a pv/@type of an xref/@pvtype, map to a CSS class for presentation
  253. function MapPVTypeToCSSClass(sPVType, oData, sDevLang)
  254. {
  255.     if (!sPVType)
  256.     {
  257.         return false;
  258.     }
  259.     
  260.     switch(sPVType)
  261.     {
  262.         case 'range':
  263.             oData.className = 'clsRange';
  264.             break;
  265.         case 'literal':
  266.             oData.className = 'clsLiteral';
  267.             break;
  268.         case 'flag':
  269.             if (sDevLang == 'scr')
  270.             {
  271.                 oData.className = 'clsLiteral';
  272.             }
  273.             else
  274.             {
  275.                 oData.className = 'clsFlag';
  276.             }
  277.             
  278.             break;
  279.         otherwise:
  280.             oData.error = "unsupported pvtype '" + sType + "'. Use (range|literal|flag)."
  281.             return false;
  282.     }
  283.     
  284.     return true;
  285. }
  286.  
  287. function GetPVCaption(oSrc, oData)
  288. {
  289.     return oData.caption;
  290. }
  291.  
  292. function GetPVClass(oSrc, oData)
  293. {
  294.     return oData.className;
  295. }
  296.  
  297. function GetLastError(o)
  298. {
  299.     return (o && o.error ? o.error : "unexpected error");
  300. }
  301.  
  302. ]]>
  303.